﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace AsyncController.Controllers
{
    public class HomeController : System.Web.Mvc.AsyncController
    {

        public ActionResult Index()
        {
            return View();
        }

        [AsyncTimeout(2000)]
        //[HandleError(ExceptionType = typeof(TaskCanceledException), View = "TimedOut")]
        public async Task<ActionResult> Photo(CancellationToken cancellationToken)
        {
            var client = new HttpClient();
            var photosRequest = new HttpRequestMessage(HttpMethod.Get, "http://getdev.net/Content/Images/Logo_GetDev_eng.png");
            var response = await client.SendAsync(photosRequest, cancellationToken);
            var bytes = await response.Content.ReadAsByteArrayAsync();
            return new FileContentResult(bytes, "image/png");
        }

    }
}
